Skip to content

Make import VAR ?= default revert to default when env-var is unset#54

Merged
typeless merged 1 commit into
mainfrom
fix/import-cache-default-precedence
May 28, 2026
Merged

Make import VAR ?= default revert to default when env-var is unset#54
typeless merged 1 commit into
mainfrom
fix/import-cache-default-precedence

Conversation

@typeless

Copy link
Copy Markdown
Owner

Summary

  • process_import previously resolved env-var values in the order env → cache → default, with the cache populated unconditionally on every build by ensure_env_var_node. Once a value entered the cache it recycled forever; the default branch was unreachable for any author who had built once with the env var set.
  • Swap to env → default → cache. A written ?= default is the explicit revert-target for the env-unset case and now wins over the cache. Plain import VAR without a default still falls back to the cache, preserving the cross-shell stability the cache was added for.

Test plan

  • New scenario import ?= default reverts when env is unset on warm index ([e2e][import]) — sets MY_VAR=from_env, builds, drops EnvGuard, rebuilds, asserts out.txt is the default, not the cached env value. Red before, green after.
  • [e2e][import] — all 7 scenarios pass (80 assertions). env_var_persist (load-bearing for the no-default cache-stickiness path) still green.
  • [phi] — 84 assertions, 9 scenarios.
  • [platform-incremental] (PR Fold env-driven conditionals into command identity #53 reproducer) — green.
  • [envdep] (PR Identify commands by a structural hash, not a string or position #52 sticky-edge reproducer) — green.
  • make test — 23679 assertions, 467 cases.
  • make format, make iwyu clean. make tidy warnings unchanged from main (pre-existing readability-qualified-auto on the same std::lower_bound line).

🤖 Generated with Claude Code

process_import resolved env-var values in the order env -> cache -> default. The cache was populated unconditionally by ensure_env_var_node on every build, so once a value entered the cache it recycled through every subsequent build and the default branch was unreachable. The user had no way to revert to the written default by unsetting the env var; only putup clean (or hand-editing the index) dropped the cached value.

Swap to env -> default -> cache. When the author wrote `?= default`, that default is the explicit revert-target for the env-unset case and now wins over the cache. Plain `import VAR` without a default still falls through to the cache, so the cross-shell stability that motivated the cache in the first place (build with MY_VAR=foo, open a fresh shell that forgot the export, rebuild without surprise) is preserved.

Reproducer: [e2e][import] test "import ?= default reverts when env is unset on warm index" - sets MY_VAR=from_env, builds, drops the EnvGuard, rebuilds, asserts out.txt reads "default_value" not the cached "from_env". Red before, green after. Full suite green (467 cases, 23679 assertions); [phi], [platform-incremental], [envdep] untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@typeless typeless merged commit 3ea023f into main May 28, 2026
9 checks passed
@typeless typeless deleted the fix/import-cache-default-precedence branch May 28, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant